﻿using T4UtilityBelt.DataDesigns;
using T4UtilityBelt.Writers;

namespace T4UtilityBelt.UxDesigns.Controls.Renderers.Windows
{
    public class ParentOneRenderer : ParentRenderer<ParentOneControl, IParentOneRenderer, ParentOne>, IParentOneRenderer
    {
        protected override void OnRenderUiXmlContentInput(ParentOneControl control, CodeWriter writer)
        {
            //<ComboBox Controls:HelpText.Text="<#=name#>tt" ItemsSource="{Binding <#=toEntity#>List}"
            //         DisplayMemberPath="Title"
            //         SelectedValuePath="Id"
            //         SelectedValue="{Binding Entry.<#=name#>Id, Mode=TwoWay}" />
            writer.WriteBeginTag("ComboBox");
            RenderControlAttributes(control, writer);
            //writer.WriteAttribute("Controls:HelpText.Text", control.HelpText);
            writer.WriteAttribute("ItemsSource", string.Format(@"{{Binding {0}List}}", control.Property.ToName));
            writer.WriteAttribute("DisplayMemberPath", "Title");
            writer.WriteAttribute("SelectedValuePath", "Id");
            //writer.WriteAttribute("SelectedValue", string.Format(@"{{Binding {0}Id,  Mode=TwoWay}}", GetBindingContext(control)));

            writer.WriteFullEnd();
        }

        protected override void OnRenderUiXmlContentReadOnly(ParentOneControl control, CodeWriter writer)
        {
            //<TextBlock    Text="{Binding  Entry.<#=name#>, Converter={StaticResource iModelText}}" />
            writer.WriteBeginTag("TextBlock");
            //RenderControlAttributes(control, writer);
            if (control.Style == null)
            {
                writer.WriteAttribute("Style", "{StaticResource ReadonlyTextBlock}");
            }
            else
            {
                writer.WriteAttributeFormat("Style", @"{{StaticResource {0}}}", control.Style);
            }

            //writer.WriteAttribute("Text", string.Format(@"{{Binding {0}, Converter={{StaticResource iModelText}}}}", GetBindingContext(control)));

            writer.WriteFullEnd();
        }

        protected override void OnRenderViewModelCs(ParentOneControl control, CodeWriter writer)
        {
            writer.WriteFormatLine(
@"      public {0}Collection {0}List
        {{
            get
            {{
                return {0}Pickers.Items().Result;
            }}
        }}
",
            control.Property.ToName
);
        }
    }
}